package com.chen.service.impl;

import com.chen.base.PageResponse;
import com.chen.dto.NursingProjectDto;
import com.chen.entity.NursingProject;
import com.chen.mapper.NursingProjectMapper;
import com.chen.service.NursingProjectService;
import com.chen.vo.NursingProjectVo;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 *  护理项目Service实现类
 * @author: ChenFY
 * @date: 2024/7/22
 */
@Service
public class NursingProjectServiceImpl implements NursingProjectService {
    @Resource
    private NursingProjectMapper nursingProjectMapper;

    /**
     * 分页查询护理项目列表
     */
    @Override
    public PageResponse<NursingProjectVo> getByPage(String name, Integer status, Integer pageNum, Integer pageSize) {
        //分页查询
        PageHelper.startPage(pageNum, pageSize);
        //分页查询
        Page<NursingProject> nursingProjects = nursingProjectMapper.selectByPage(name, status, pageNum, pageSize);
        //bean拷贝
        PageResponse<NursingProjectVo> projectVoPageResponse = PageResponse.of(nursingProjects, NursingProjectVo.class);

        return projectVoPageResponse;
    }

    /**
     * 新增护理项目
     */
    @Override
    public void add(NursingProjectDto nursingProjectDTO) {
        NursingProject nursingProject = new NursingProject();
        BeanUtils.copyProperties(nursingProjectDTO, nursingProject);
        nursingProjectMapper.insert(nursingProject);
    }
    /**
     * 根据编号查询护理项目信息
     */
    @Override
    public NursingProjectVo getById(Long id) {
        NursingProject nursingProject = nursingProjectMapper.selectById(id);
        NursingProjectVo nursingProjectVO = new NursingProjectVo();
        BeanUtils.copyProperties(nursingProject, nursingProjectVO);
        return nursingProjectVO;
    }
    /**
     * 更新护理项目信息
     */
    @Override
    public void update(NursingProjectDto nursingProjectDTO) {
        NursingProject nursingProject = new NursingProject();
        BeanUtils.copyProperties(nursingProjectDTO, nursingProject);
        nursingProjectMapper.update(nursingProject);
    }
    /**
     * 删除护理项目信息
     */
    @Override
    public void deleteById(Long id) {
        nursingProjectMapper.deleteById(id);
    }
    /**
     * 启用/ 禁用护理项目
     */
    @Override
    public void enableOrDisable(Long id, Integer status) {
        nursingProjectMapper.updateStatus(id, status);
    }
    /**
     * 查询所有护理项目
     */
    @Override
    public List<NursingProjectVo> listAll() {
        return nursingProjectMapper.listAll();
    }
}
